class BiliApiController < ApplicationController
  before_filter :login_required
  layout "need_login"
  def index
    @apps = App.all
  end

  def app_add
    App.create params[:app]
    redirect_to :action => :index
  end

  def app_remove
    App.destroy params[:id]
    redirect_to :action => :index
  end

  def keys_list
    @keys = Key.find_all_by_app_id params[:id]
  end

  def key_add
    Key.create params[:key]
    redirect_to :back
  end

  def key_edit
    @key = Key.find params[:id]
  end

  def key_remove
    Key.destroy params[:id]
    redirect_to :back
  end

  def key_update
    Key.update params[:key][:id], params[:key]
    redirect_to :back
  end

  def uname_add
    params[:user][:unames].split(',').each do |uname|
      KeyUser.create :key_id => params[:user][:id], :uname => uname
    end
    redirect_to :back
  end

  def uname_remove
    KeyUser.destroy params[:id]
    redirect_to :back
  end

end
